import { FC, useRef } from "react";

const UseRefCom: FC<any> = () => {
    let ipt = useRef<HTMLInputElement | null>(null)
    
    // 坑：对于li这类元素，声明类型时初始值直接给null就行了
    let lis=useRef(null)
    let handleClick = () => {
        console.log(ipt);
        ipt.current!.focus()
    }
    return (
        <fieldset>
            <legend>使用ref</legend>
            <input type="text" name="" id="" ref={ipt} />
            <ul>
                <li  ref={lis}>1</li>
            </ul>
            <button onClick={handleClick}>点击获得焦点</button>
        </fieldset>
    )
}
export default UseRefCom